$( document ).ready(function() {
	$("#messageDiv").empty();
	$("#messageDiv").hide();
    $.getJSON("patient/lookupPatientInfo.html" ,function(data){
    	var dateOfBirth=new Date(data.patientInfo.dateOfBirth);
    	$("[name='firstname']").val(data.patientInfo.firstname);
    	$("[name='lastname']").val(data.patientInfo.lastname);
    	/*
    	$("[name='year']").val(dateOfBirth.getFullYear());
    	$("[name='month']").val(dateOfBirth.getMonth()+1);
    	$("[name='day']").val(dateOfBirth.getDate());
    	*/
    	$("#dateOfBirth").datepicker("setDate",dateOfBirth);
    	$("#dateOfBirth").datepicker("update");
    	
    	if(data.patientInfo.gender=='m'){
    		$("[name='gender']").val("male");
    	}else{
    		$("[name='gender']").val("female");
    	}
    	$("[name='phoneNum']").val(data.patientInfo.phonenum);
    	$("[name='cellphone']").val(data.patientInfo.cellphone);
    	$("[name='email']").val(data.patientInfo.email);
    	$("[name='address']").val(data.patientInfo.address);
    	$("[name='postalCode']").val(data.patientInfo.postalCode);
    	$("[name='currentHealth']").val(data.patientInfo.currentHealth);
    });
});

function updateInfo(){
	$.getJSON("patient/updatePatientInfo.html?firstname="+$("[name='firstname']").val()+
											"&lastname="+$("[name='lastname']").val()+
											/*
											"&year="+$("[name='year']").val()+
											"&month="+$("[name='month']").val()+
											"&day="+$("[name='day']").val()+
											*/
											"&date="+$("#dateOfBirth").val()+
											
											"&gender="+$("[name='gender']").val()+
											
											"&phoneNum="+$("[name='phoneNum']").val()+
											"&cellphone="+$("[name='cellphone']").val()+
											"&email="+$("[name='email']").val()+
											"&address="+$("[name='address']").val()+
											"&postalCode="+$("[name='postalCode']").val()+
											"&currentHealth="+$("[name='currentHealth']").val(), function(data){
		if(data.flag==true){
			$("#messageDiv").removeClass("success");
			$("#messageDiv").removeClass("error");
			$("#messageDiv").addClass("success");
			$("#messageDiv").html("<strong>"+data.message+"</strong>");
			$("#messageDiv").show();
		}else if(data.flag==false){
			$("#messageDiv").removeClass("success");
			$("#messageDiv").removeClass("error");
			$("#messageDiv").addClass("error");
			$("#messageDiv").html("<strong>"+data.message+"</strong>");
			$("#messageDiv").show();
		}
	});
}